package com.lee.ssm.controller;

import com.lee.ssm.domain.Permission;
import com.lee.ssm.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private IPermissionService iPermissionService;
    @RequestMapping("/findAll")
    public ModelAndView findAll() throws Exception{
        ModelAndView mv=new ModelAndView();
        List<Permission> list= iPermissionService.findAll();
        mv.setViewName("permission-list");
        mv.addObject("permissionList",list);
        return mv;
    }
    @RequestMapping("/save")
    public String save(Permission permission) throws Exception{
        iPermissionService.save(permission);

        return "redirect:findAll.do";
    }
    @RequestMapping("/findById")
    public ModelAndView findById( String id ) throws Exception{
        ModelAndView mv=new ModelAndView();
        Permission permission= iPermissionService.findById(id);
        mv.setViewName("permission-show");
        mv.addObject("permission",permission);
        return mv;
    }
    @RequestMapping("/deleteById")
    public String deleteById(String id) throws Exception {
        iPermissionService.deleteById(id);
        return "redirect:findAll.do";
    }
}
